import { EzGameNetManager, PushMsgMeta } from "./base/EzGameNetManager";
import { EzGameUtils } from "./base/EzGameProtoMsgCodecs";
import * as sync_pb from "./entity/sync_entity";

/**
 * 自动生成的代码
 */
export class SyncPushMsgEnum{
    static serverName:string="default"

    public static readonly Move:PushMsgMeta<sync_pb.MoveResp> = {
        cmd:999,
        decoder:(data:Uint8Array)=>{
            return EzGameUtils.objDataDecode(sync_pb.MoveRespSchema,data) as sync_pb.MoveResp
        }
    };
    
    public static addListener<T>(meta:PushMsgMeta<T>, handler:(data:T)=>void):void {
        let handlerMap = EzGameNetManager.getServerPushHandlerMap(this.serverName);
        let exist = handlerMap.get(meta.cmd)
        if(exist) {
            console.error(`命令 ${meta.cmd} 已经存在监听器，将被新的监听器覆盖`);
        }
        meta.handler = handler
        handlerMap.set(meta.cmd, meta);
    }
}

